package com.sup.sale.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sup.common.annotation.Log;
import com.sup.common.core.controller.BaseController;
import com.sup.common.core.domain.AjaxResult;
import com.sup.common.enums.BusinessType;
import com.sup.sale.domain.SalesTable;
import com.sup.sale.service.ISalesTableService;
import com.sup.common.utils.poi.ExcelUtil;
import com.sup.common.core.page.TableDataInfo;

/**
 * 销售Controller
 * 
 * @author ruoyi
 * @date 2025-06-25
 */
@RestController
@RequestMapping("/sale/sale")
public class SalesTableController extends BaseController
{
    @Autowired
    private ISalesTableService salesTableService;

    /**
     * 查询销售列表
     */
    @PreAuthorize("@ss.hasPermi('sale:sale:list')")
    @GetMapping("/list")
    public TableDataInfo list(SalesTable salesTable)
    {
        startPage();
        List<SalesTable> list = salesTableService.selectSalesTableList(salesTable);
        return getDataTable(list);
    }

    /**
     * 导出销售列表
     */
    @PreAuthorize("@ss.hasPermi('sale:sale:export')")
    @Log(title = "销售", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SalesTable salesTable)
    {
        List<SalesTable> list = salesTableService.selectSalesTableList(salesTable);
        ExcelUtil<SalesTable> util = new ExcelUtil<SalesTable>(SalesTable.class);
        util.exportExcel(response, list, "销售数据");
    }

    /**
     * 获取销售详细信息
     */
    @PreAuthorize("@ss.hasPermi('sale:sale:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(salesTableService.selectSalesTableById(id));
    }

    /**
     * 新增销售
     */
    @PreAuthorize("@ss.hasPermi('sale:sale:add')")
    @Log(title = "销售", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SalesTable salesTable)
    {
        return toAjax(salesTableService.insertSalesTable(salesTable));
    }

    /**
     * 修改销售
     */
    @PreAuthorize("@ss.hasPermi('sale:sale:edit')")
    @Log(title = "销售", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SalesTable salesTable)
    {
        return toAjax(salesTableService.updateSalesTable(salesTable));
    }

    /**
     * 删除销售
     */
    @PreAuthorize("@ss.hasPermi('sale:sale:remove')")
    @Log(title = "销售", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(salesTableService.deleteSalesTableByIds(ids));
    }
}
